//
//  VideoTableViewCell.m
//  MansApp
//
//  Created by lanou3g on 15/7/18.
//  Copyright (c) 2015年 ACH. All rights reserved.
//

#import "VideoTableViewCell.h"

@implementation VideoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.text = [[UILabel alloc]initWithFrame:CGRectZero];
        [self.contentView addSubview:_text];
        
        self.videouri = [[UIImageView alloc]initWithFrame:CGRectZero];
        [self.contentView addSubview:_videouri];
        
        self.playButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.videouri addSubview:_playButton];
    }
    return self;
}
- (void)setValueModel:(VideoModel *)model
{
    CGRect bounds = [model.text boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    self.text.frame = CGRectMake(kP6Height(20), kP6Height(10), kWidth - kP6Height(40), bounds.size.height);
    self.text.text = model.text;
    self.text.numberOfLines = 0;
    self.text.font = [UIFont fontWithName:@"Georgia-BoldItalic" size:15];
    
    NSURL *url = [NSURL URLWithString:model.videouri];
    [self.videouri sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"5.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        self.height = image.size.height;
    }];
    self.videouri.frame = CGRectMake(kP6Height(20), self.text.frame.size.height + kP6Height(20),kWidth - kP6Height(40),kP6Height(180));
    self.playButton.frame = CGRectMake((kWidth / 2) - kP6Height(55), self.videouri.frame.size.height / 2 - kP6Height(30), kP6Height(60), kP6Height(60));
    [self.playButton setBackgroundImage:[UIImage imageNamed:@"VideoPlay@2x 2.png"] forState:UIControlStateNormal];
}
//动态返回高度
- (CGFloat)height:(VideoModel *)model
{
    NSURL *url = [NSURL URLWithString:model.videouri];
    [self.videouri sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"5.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        self.height = image.size.height;
    }];
    //NSInteger scale = self.picWidth / (kWidth - kP6Height(40));
    CGRect bounds = [model.text boundingRectWithSize:CGSizeMake(300, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    
    return kP6Height(180) + kP6Height(30) + (bounds.size.height);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
